package com.sss.hloster07;

import java.util.Scanner;

public class JavaExercise36 {

	public static void main(String[] args) {
		test36();
	}

	/**
	 * n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
	 */
	private static void test36() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请问要输入几个整数：");
		int n = sc.nextInt();
		int arr[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			System.out.println("请输入第"+(i+1)+"个整数：");
			arr[i] = sc.nextInt();
		}
		System.out.print("您输入的整数数组为：");
		for (int i = 0; i < n; i++) {
			System.out.print(arr[i] + "  ");
		}
		System.out.println();
		System.out.println("前面各数向后移动几个位置：");
		int m = sc.nextInt();
		int arr01[] = new int[m];
		for (int i = 0; i < m; i++) {
			arr01[i] = arr[n - m + i];
		}
		for (int i = n - 1; i >= m; i--) {
			arr[i] = arr[i - m];
		}
		for (int i = 0; i < m; i++) {
			arr[i] = arr01[i];
		}
		System.out.print("位移之后的数组是：");
		for (int i = 0; i < n; i++) {
			System.out.print(arr[i] + "   ");
		}
	}
}
